package com.sk.bilibili.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sk.bilibili.bean.*;
import com.sk.bilibili.dto.SearchInfo;
import com.sk.bilibili.other.R;
import com.sk.bilibili.service.SearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
* @author 邵康
* @date 2021/11/23 21:07
*/
@CrossOrigin
@RestController
@RequestMapping("/search")
@Api(tags = "搜索")
public class SearchController {

    @Autowired
    private SearchService searchService;

    @ApiOperation("add")
    @PostMapping("/add")
    public R<Void> add(@RequestBody Search search){
        return searchService.add(search);
    }

    @ApiOperation("删除搜索记录")
    @GetMapping("/delete")
    public R<Void> delete(Integer id){
        return searchService.delete(id);
    }

    @ApiOperation("update")
    @PostMapping("/update")
    public R<Void> update(@RequestBody Search search){
        return searchService.update(search);
    }

    @ApiOperation("page")
    @GetMapping("/page")
    public R<IPage<Search>> page( @RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer size){
        return searchService.page(page,size);
    }

    @ApiOperation("搜索视频功能   默认搜索 就是这个  会记录记录 只有 keyword是必须的")
    @PostMapping("/searchVideo")
    public R<IPage<VideoSet>> searchVideo(@RequestBody SearchInfo searchInfo){
        return searchService.searchVideo(searchInfo);
    }

    @ApiOperation("手动添加历史记录 因为搜索会刷新发多次请求导致")
    @GetMapping("/addSearchHistory")
    public R<Void> addSearchHistory(String keyword){
        return searchService.addSearchHistory(keyword);
    }

    @ApiOperation("搜索番剧 国创等")
    @PostMapping("/searchThem")
    public R<IPage<Them>> searchThem(@RequestBody SearchInfo searchInfo){
        return searchService.searchThem(searchInfo);
    }

    @ApiOperation("搜索人员")
    @PostMapping("/searchMember")
    public R<IPage<Member>> searchMember(@RequestBody SearchInfo searchInfo){
        return searchService.searchMember(searchInfo);
    }

    @ApiOperation("搜索直播")
    @PostMapping("/searchLive")
    public R<IPage<Live>> searchLive(@RequestBody SearchInfo searchInfo){
        return searchService.searchLive(searchInfo);
    }

    @ApiOperation("动态搜索提示")
    @GetMapping("/searchTip")
    public R<List<String>> searchTip(String keyword){
        return searchService.searchTip(keyword);
    }

    @ApiOperation("获取当前用户的所有搜索记录")
    @GetMapping("/getHistory")
    public R<List<Search>> getHistory(){
        return searchService.getHistory();
    }

    @ApiOperation("删除当前用户的所有搜索记录")
    @GetMapping("/deleteAll")
    public R<Void> deleteAll(){
        return searchService.deleteAll();
    }

    @ApiOperation("随机获取指定条搜索记录  用于提示热搜")
    @GetMapping("/getRandom")
    public R<List<Search>> getRandom(Integer size){
        return searchService.getRandom(size);
    }

}
